<template>
	<view :style="themeColor">
		<view class="page">
			<view class="flex flex-direction align-stretch justify-between benben-position-layout flex search_flex_0"
				:style="{height:(93+StatusBarRpx)+'rpx',paddingTop:StatusBarRpx+'rpx', }">
				<view class='flex flex-wrap align-center justify-between search_fd0_0'>
					<view class='flex flex-wrap align-center flex-sub search_fd0_0_c0'>
						<image class='search_fd0_0_c0_c0' mode="aspectFit" :src='STATIC_URL+"16.png"' @tap.stop="addSearchHistoryFunc"></image>
						<input class='flex-sub search_fd0_0_c0_c1' type="text" :placeholder="`请输入搜索内容`"
							confirm-type="done" :maxlength="-1"
							placeholder-style="color:rgba(153, 153, 153, 1);font-size:28rpx"
							@confirm="addSearchHistoryFunc()" v-model="keywords" />
					</view>
					<text class='search_fd0_0_c1' @tap.stop="handleJumpDiy" data-type="back" data-url="1">取消</text>
				</view>

			</view>
			<view :style="{height: (93+StatusBarRpx)+'rpx'}"></view>
			<!---搜索记录flex布局开始-->
			<view class="flex flex-direction flex-wrap align-stretch benben-flex-layout search_flex_1">
				<view class='flex flex-wrap align-center search_fd1_0'>
					<!-- v-if="appSearchHistory.length!=0" -->
					<text class='search_fd1_0_c0'>历史搜索</text>
					<image class='search_fd1_0_c1' mode="aspectFit" :src='STATIC_URL+"158.png"'
						@tap.stop="popupShow1695196431623=true"></image>
					<!-- v-if="appSearchHistory.length!=0" -->
				</view>
				<!-- v-if=" appSearchHistory.length!=0" -->
				<view class='flex flex-wrap align-center search_fd1_1'>
					<view v-for="(item,index) in historySearchArr" :key="index" class='flex flex-wrap align-center search_fd1_1_c0' @tap.stop="handleJumpDiy"
						data-type="navigateTo" :data-url="`/pages/ss/searchResult/searchResult?keywords=${item}`">
						<text class='search_fd1_1_c0_c0'>{{item}}</text>
						<image class='search_fd1_1_c0_c1' mode="aspectFit" :src='STATIC_URL+"159.png"'
							@tap.stop="deleteSearchHistoryFunc(index)"></image>
					</view>
				</view>
				<image v-if="historySearchArr.length == 0" class='search_fd1_2' mode="aspectFit" :src='STATIC_URL+"17.png"'></image>
				<!-- v-if="appSearchHistory.length==0" -->
			</view>

			<!---搜索记录flex布局结束-->
			<benben-popup v-model="popupShow1695196431623" :mask="true" :mask-close-able="true" mode='center'>
				<!---删除历史记录弹窗flex布局开始-->
				<view class="flex flex-direction flex-wrap align-center search_flex_2">
					<text class='search_fd2_0'>确定删除历史记录？</text>
					<view class='flex flex-wrap align-center search_fd2_1'>
						<button class='search_fd2_1_c0' @tap.stop="popupShow1695196431623=false">取消</button>
						<button class='search_fd2_1_c1' @tap.stop="emptySearchHistoryFunc()">确定</button>
					</view>
				</view>

				<!---删除历史记录弹窗flex布局结束-->

			</benben-popup>


		</view>
	</view>
</template>
<script>
	export default {
		components: {},


		data() {
			return {
				"popupShow1695196431623": false,
				"removeIndex": -1,
				"keywords": "",
				historySearchArr:[],
				currentIndex:'',
			};
		},
		computed: {
			themeColor() {
				return this.$store.getters.themeColor
			},
			appSearchHistory() { // 搜索历史
				return this.$store.state.appSearchHistory
			}
		},
		watch: {},
		onLoad(options) {

		},
		onUnload() {

		},
		onReady() {

		},
		onShow() {
			let hisArr = uni.getStorageSync('searchArr')
			if(hisArr.length != '0'){
				this.historySearchArr = [...new Set(hisArr)]
			}
			console.log(this.historySearchArr);
		},
		onHide() {

		},
		onResize() {

		},
		onPullDownRefresh() {

		},
		onReachBottom(e) {

		},
		onPageScroll(e) {

		},
		methods: {
			//清空搜索记录
			emptySearchHistoryFunc() {
				this.$store.commit('appSearchHistoryClean', '')
				this.popupShow1695196431623 = false;
				uni.removeStorageSync('searchArr')
				this.historySearchArr = []
				this.keywords = ''
			},
			//长按事件
			handleLongpressFunc(index) {
				this.removeIndex = index;
			},
			//删除搜索历史
			deleteSearchHistoryFunc(index) {
				// this.$store.commit('appSearchHistoryDel', {
				// 	"name": name
				// })
				this.currentIndex = index
				this.historySearchArr.splice(this.currentIndex, 1);
				uni.setStorageSync('searchArr', this.historySearchArr);
			},
			//添加搜索历史
			addSearchHistoryFunc() {
				if(!this.keywords){
					this.$message.info('请输入关键字')
				}else{
					this.historySearchArr.push(this.keywords)
					this.$store.commit('appSearchHistoryAdd', {
						"name": this.keywords
					})
					uni.setStorageSync('searchArr', this.historySearchArr);
					uni.navigateTo({
						url:`/pages/ss/searchResult/searchResult?keywords=${this.keywords}`
					})
				}
			}
		}
	};
</script>
<style lang="scss" scoped>
	.page {
		width: 100vw;
		overflow-x: hidden;
		min-height: calc(100vh - var(--window-bottom));
		background: var(--benbenbgColor1);
		background-size: 100% auto;
	}

	.search_flex_0 {
		background: #fff;
		width: 750rpx;
		height: 93rpx;
		overflow: hidden;
		z-index: 10;
		top: 0rpx;
		background-size: #eee;
	}

	.search_fd0_0_c1 {
		color: #333333;
		font-size: 28rpx;
		font-weight: 400;
		line-height: 30rpx;
		margin: 0rpx 0rpx 0rpx 32rpx;
	}

	.search_fd0_0_c0_c1 {
		font-size: 24rpx;
		font-weight: 400;
		color: #333;
	}

	.search_fd0_0_c0_c0 {
		width: 26rpx;
		height: 26rpx;
		border-radius: 0rpx 0rpx 0rpx 0rpx;
		margin: 0rpx 16rpx 0rpx 0rpx;
	}

	.search_fd0_0_c0 {
		background: #F5F5F5;
		height: 64rpx;
		background-size: 100% auto !important;
		border-radius: 34rpx 34rpx 34rpx 34rpx;
		padding: 0rpx 24rpx 0rpx 24rpx;
		font-size: 28rpx;
		font-weight: 400;
		color: #333;
		width: 598rpx;
	}

	.search_fd0_0 {
		padding: 10rpx 32rpx 0rpx 32rpx;
		line-height: 93rpx;
	}

	.search_flex_1 {
		padding: 0rpx 0rpx 0rpx 0rpx;
	}

	.search_fd1_2 {
		width: 280rpx;
		height: 269rpx;
		border-radius: 0rpx 0rpx 0rpx 0rpx;
		margin: 275rpx 0rpx 0rpx 235rpx;
	}

	.search_fd1_1_c0_c1 {
		width: 18rpx;
		height: 18rpx;
		border-radius: 0rpx 0rpx 0rpx 0rpx;
	}

	.search_fd1_1_c0_c0 {
		font-size: 28rpx;
		font-weight: 400;
		color: #333333;
		margin: 0rpx 16rpx 0rpx 0rpx;
		line-height: 34rpx;
	}

	.search_fd1_1_c0 {
		border-radius: 20rpx 20rpx 20rpx 20rpx;
		padding: 0rpx 36rpx 0rpx 12rpx;
		line-height: 56rpx;
		margin: 0rpx 12rpx 24rpx 12rpx;
		height: 56rpx;
	}

	.search_fd1_1 {
		padding: 0rpx 0rpx 0rpx 12rpx;
	}

	.search_fd1_0_c1 {
		width: 24rpx;
		height: 28rpx;
		border-radius: 0rpx 0rpx 0rpx 0rpx;
		margin: 0rpx 0rpx 0rpx auto;
	}

	.search_fd1_0_c0 {
		font-size: 32rpx;
		font-weight: 500;
		color: #333333;
		line-height: 35rpx;
	}

	.search_fd1_0 {
		padding: 32rpx 0rpx 24rpx 0rpx;
		margin: 0rpx 32rpx 0rpx 32rpx;
	}

	.search_flex_2 {
		background: #fff;
		margin: 0rpx 105rpx 0rpx 105rpx;
		background-size: #eee;
		border-radius: 25rpx 25rpx 25rpx 25rpx;
	}

	.search_fd2_1_c1 {
		background: transparent;
		line-height: 110rpx;
		border-radius: 0rpx 0rpx 16rpx 0rpx;
		font-size: 32rpx;
		color: rgba(252, 95, 128, 1);
		width: 269rpx;
		height: 110rpx;
	}

	.search_fd2_1_c0 {
		border-right: 1px solid #EEEEEE;
		background: transparent;
		line-height: 110rpx;
		border-radius: 0rpx 0rpx 0rpx 16rpx;
		font-size: 32rpx;
		color: var(--benbenFontColor2);
		height: 110rpx;
		width: 270rpx;
	}

	.search_fd2_1 {
		border-top: 1px solid #eee;
	}

	.search_fd2_0 {
		font-size: 32rpx;
		font-weight: 500;
		line-height: 52rpx;
		color: #333333;
		margin: 90rpx 0rpx 89rpx 0rpx;
	}
</style>